package edu.zzuli.model.xt.pzzc.xtgngl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Controller;

import edu.zzuli.common.Pagination;
import edu.zzuli.model.core.JqGridBaseAction;
import edu.zzuli.model.orm.po.GG_XTGN;
import edu.zzuli.model.xt.pzzc.xtgngl.iface.XtgnglService;

/**
 * @author tianshaojie
 * @date 2011-8-12
 * @discription :
 */
@SuppressWarnings("serial")
@Controller
public class ListXtgnglAction extends JqGridBaseAction<GG_XTGN>{
	
	@Resource
	private XtgnglService xtgnglService;
	
	private String ajaxResult;
	
	public String execute() {
		return this.refreshGridModel();
	}
	
	public List<GG_XTGN> listResults(Pagination pagination) {
		String fid = ServletActionContext.getRequest().getParameter("fid");
		fid = fid == null ? "ROOT" : fid;
//		String sql = "select * from gg_xtgn where fid = '" + fid + "' order by sxh";
		String sql = "select id,jdmc,gndz,jdlb,fid from gg_xtgn where fid = :FID order by sxh";
		MapSqlParameterSource paramMap = new MapSqlParameterSource();
		paramMap.addValue("FID", fid);
		return xtgnglService.selectSplit(sql,paramMap,pagination);
	}
	
	public String delete() {
		String ids = ServletActionContext.getRequest().getParameter("id");
		try {
			if (ids != null && !"".equals(ids)) {
				this.xtgnglService.deleteGG_XTGN(ids);
				this.ajaxResult = "success";
			} else {
				this.ajaxResult = "error";
			}
		} catch (Exception e) {
			e.printStackTrace();
			this.ajaxResult = "error";
		}
		return this.ajaxResult;
	}

	public void setAjaxResult(String ajaxResult) {
		this.ajaxResult = ajaxResult;
	}

	public String getAjaxResult() {
		return ajaxResult;
	}
}
